package com.lt.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lt.crm.pojo.CstLost;
import com.lt.crm.pojo.SysUser;
import com.lt.crm.service.CstLostService;
import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Controller
public class LostController {
    @Resource
     CstLostService cstLostService;

    @RequestMapping(value = "/lost/list")
    public String lostlist(Model model, String lstCustName, String lstCustManagerName, @RequestParam(required = false, defaultValue = "1") int pageIndex) {
//        Sort sort = Sort.by(Sort.Direction.ASC, "lstId");
//        //控制分页的辅助类，可以设置页码(从0开始！！！)、每页的数据条数、排序等
//        Pageable pageable = PageRequest.of(pageIndex - 1, 5, sort);
        Page<CstLost> page =new  Page<>(pageIndex, 5);
        Page<CstLost> lostPage = cstLostService.findLost(lstCustName, lstCustManagerName, page);
        model.addAttribute("rolePage", lostPage);
        model.addAttribute("lstCustName", lstCustName);
        model.addAttribute("lstCustManagerName", lstCustManagerName);
        List<CstLost> roles = cstLostService.list();
        model.addAttribute("chance", roles);
        return "lost/list";
    }

    @RequestMapping(value = "/lostc/edit")
    public String edit(@RequestParam("lstId") Integer lstId, Model model) {
        QueryWrapper<CstLost> queryWrapper = new QueryWrapper();
        queryWrapper.eq("lst_id", lstId);
        CstLost losts = cstLostService.getOne(queryWrapper);
        model.addAttribute("losts", losts);
        return "lost/edit";
    }

    @RequestMapping(value = "/lost/save")
    public String save(CstLost lost) {
        cstLostService.saveOrUpdate(lost);
        return "redirect:/lost/list";
    }
}
